package com.decent.common.enums;

/**
 * 全局http错误编码，编写状态码时code需要保证类中唯一，并且按照从小到大的顺序排列
 *
 * @author wangyan
 */
public enum ErrorCodeEnum {
    /**
     * 错误码
     */
    REQUEST_TIMEOUT(0, "请求超时"),
    OK(200, "请求通过"),
    NO(201, "请求不通过"),
    UNAUTHORIZED(401, "身份未认证"),
    ILLEGAL_AUTHORIZE(403, "暂无操作权限"),
    THE_INTERVAL_OF_DATA_IS_TOO_LONG(202, "限制查询7天间隔内的数据"),
    TOKEN_TIMEOUT(1001, "授权失效"),
    TOKEN_INVALID(1002, "授权失败"),


    INVALID_PARAMS(9001, "参数有误"),
    DATA_ALREADY_EXISTS(9005, "数据已存在"),
    DATA_NOT_FOUND(9004, "数据不存在"),
    INSERT_THE_FAILURE(9007, "数据新增失败"),
    MODIFY_THE_FAILURE(9006, "数据修改失败"),
    DELETE_THE_FAILURE(9008, "数据删除失败"),
    UPDATE_STATUS_FAILED(9021, "更新状态失败"),
    REQUEST_METHOD_NOT_SUPPORTED(9998, "请求方法不受支持"),
    ERROR(9999, "系统异常"),
    NOTIFY_FAIL(80181, "回调通知失败"),
    /**
     * pipeline
     */
    CONTEXT_IS_NULL(9801, "流程上下文为空"),
    PROCESS_TEMPLATE_IS_NULL(9802, "流程模板配置为空"),
    PROCESS_LIST_IS_NULL(9803, "业务处理器配置为空"),
    PROCESS_MODEL_IS_NULL(9804, "处理模型为空"),
    NEED_BREAK_IS_NULL(9805, "请传入是否中断标识"),
    ;
    private final Integer code;

    private final String message;

    ErrorCodeEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    @SuppressWarnings("unused")
    public static ErrorCodeEnum getEnumByCode(Integer code) {
        ErrorCodeEnum[] enums = ErrorCodeEnum.values();
        for (ErrorCodeEnum statusEnum : enums) {
            if (statusEnum.getCode().equals(code)) {
                return statusEnum;
            }
        }
        return null;
    }
}
